package com.example.learn.hwod;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Optional;
import java.util.Scanner;

public class _30最小战斗力差值 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] array = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).sorted().toArray();
        int sum = Arrays.stream(array).sum();
        ArrayList<Integer> objects = new ArrayList<>();
        dfs(array,0,0,0,objects);
        Integer res = objects.stream().map(x -> Math.abs(sum - 2 * x)).min((a, b) -> a - b).orElse(0);
        System.out.println(res);


    }

    public static void dfs(int[] arr, int index, int level, int sum, ArrayList<Integer> res){
        if (level==5) {
            res.add(sum);
            return;
        }
        for (int i = index; i < arr.length; i++) {
            if (i > index && arr[i] == arr[i - 1])
                continue; // arr已经升序，这里进行树层去重
            dfs(arr, i + 1, level + 1, sum + arr[i], res);
        }
    }
}
